<template>
  <el-button
    :type="type"
    v-bind="$attrs"
    @click="handleOpen"
  >
    {{ text }}
  </el-button>
</template>

<script>
export default {
  name: 'Confirm',
  props: {
    text: {
      type: String,
      default: '删除'
    },
    type: {
      type: String,
      default: 'text'
    },
    confirmText: {
      type: String,
      default: '此操作将永久删除该数据, 是否继续?'
    }
  },
  data () {
    return {
    }
  },
  methods: {
    handleOpen() {
      this.$confirm(this.confirmText, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$emit('onConfirm')
      }).catch(() => {
        this.$emit('onCancel')
      })
    }
  }
}
</script>

